package com.test.action;

import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {
	private String username;
	private String password;

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String execute() throws Exception {
		if ("hello".equals(this.getUsername().trim())
				&& "world".equals(this.getPassword().trim())) {
			return "success";
		} else {
			this.addFieldError("username", "username or password error");
			return "failure";
		}

	}

	@Override
	public void validate() {
		if (null == this.getUsername() || "".equals(this.getUsername().trim())) {
			this.addFieldError("username", "username required");
		}
		if (null == this.getPassword() || "".equals(this.getPassword().trim())) {
			this.addFieldError("password", "password required");
		}
	}
}
